@extends('layouts.header')
@section('title','修改权限')
@section('content')
    <article class="page-container">
        <form class="form form-horizontal" id="form-auth-add" autocomplete="off">
            <div class="row cl">
                <label class="form-label col-sm-3">权限URL：</label>
                <div class="formControls col-sm-9">
                    <input type="text" class="input-text" value="{{ $auth_info_current->url }}" placeholder="" id="url" name="url" disabled="disabled">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-3"><span class="c-red">*</span>权限名称：</label>
                <div class="formControls col-sm-9">
                    <input type="text" class="input-text" value="{{ $auth_info_current->auth_name }}" placeholder="" id="auth_name" name="auth_name" autofocus="autofocus">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-3">权限上级：</label>
                <div class="formControls col-sm-9">
                    <span class="select-box col-sm-12" >
                        <select class="select select2 " name="pid">
                            <option value="0">作为顶级权限</option>
                            @foreach($auth_info_all as $val)
                                <option value="{{$val -> id}}" @if ($auth_info_current->pid === $val -> id) selected="selected" @endif>{{ str_repeat('---/',$val->level) }}{{$val -> auth_name}}</option>
                            @endforeach
                        </select>
                    </span>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-3">排序：</label>
                <div class="formControls col-sm-9">
                    <input type="number" class="input-text" value="{{ $auth_info_current->sort }}" placeholder="" id="sort" name="sort" style="width:150px">
                </div>
            </div>

            @csrf

            <div class="row cl pt-20">
                <div class="col-sm-9 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                    <input class="btn btn-danger radius ml-15" type="button" value="&nbsp;&nbsp;取消&nbsp;&nbsp;" onclick="layer_close();">
                </div>
            </div>
        </form>
    </article>

    <script type="text/javascript">
        $(".select2").select2();
        $(function () {
            //jQuery控制“url”表单项的动态显示和隐藏
            //初始化时默认隐藏url表单项
            // $('#url').parents('.row').hide();
            //  //给下拉列表绑定切换事件 
            // $('select').change(function(){
            //     //获取当前选中的值 
            //     var _val = $(this).val(); 
            //     //判断值 
            //     if(_val > 0){ 
            //         //显示
            //         $('#url').parents('.row').show(300);
            //     }else{ 
            //         //隐藏
            //         //重置表单项里的值 
            //         $('#url').val(''); 
            //         $('#url').parents('.row').hide(300);
            //     } 
            // });

            var index2;

            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });

            $("#form-auth-add").validate({
                rules: {
                    auth_name: {
                        required: true,
                        notSpace: true,
                        maxlength: 20
                    },
                    pid: {
                        required: true,
                    },
                    sort: {
                        required: true,
                    },
                },
                // onkeyup:false,
                // focusCleanup:false,
                success: "valid",
                submitHandler: function (form) {
                    $(form).ajaxSubmit({
                        type: 'post',
                        url: "",//自己提交给自己可以不写url   
                        beforeSend: function () {
                            //0.4透明度 白色遮罩
                            index2 = layer.load(2, {shade: [0.3, '#fff']});
                        },
                        complete: function () {
                            layer.close(index2);
                        },
                        success: function (data) {
                            //判断修改结果 
                            if (data === '1') {
                                // parent.window.location.reload();//刷新
                                parent.table_reload(0);//0停留在当前页，1回到第一页
                                parent.layer.msg('修改成功!', {icon: 1, time: 2000});
                            } else {
                                parent.layer.msg('您未做任何修改!', {icon: 6, time: 2000});
                            }
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        },
                        error: function (data) {
                            ajax_error(data);
                        }
                    });
                }
            });
        });
    </script>
@endsection